package com.chb.demo.controller;

import com.chb.demo.dao.ArtistDao;
import com.chb.demo.dao.OrderDao;
import com.chb.demo.entity.Artist;
import com.chb.demo.entity.Order;
import com.chb.demo.entity.User;
import com.chb.demo.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
public class OrderController {
    @Autowired
    OrderService orderService;
    @Autowired
    ArtistDao artistDao;


    @RequestMapping("/usermakedeal")
    @ResponseBody
    public Object login(@RequestParam("id") Integer pid, HttpSession session){
        Map<String, Object> sessionAttribute = (Map<String, Object>) session.getAttribute("map");
        User user = (User)sessionAttribute.get("INFO");
        Map<String, Object> map = orderService.makeDeal(pid,user.getAccount());
        System.out.println(map.get("success"));
        return map;
    }

    @RequestMapping("/orderDetail/{id}")
    @ResponseBody
    public void orderDetail(@PathVariable("id") Integer aid, HttpSession session){
        Artist artist = artistDao.findById(aid).get();
        System.out.println(artist.toString());
        session.setAttribute("detail",artist);
    }



}
